package cn.stylefeng.guns.modular.bi.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.service.BasicOperateService;
import cn.stylefeng.guns.modular.bi.entity.TransportRegistrationShiftSchedule;
import cn.stylefeng.guns.modular.bi.model.params.TransportRegistrationShiftScheduleParam;
import cn.stylefeng.guns.modular.bi.model.result.TransportRegistrationShiftScheduleResult;
import cn.stylefeng.guns.modular.bi.service.TransportRegistrationShiftScheduleService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 临时卡打卡班次表控制器
 *
 * @author zhangzh
 * @Date 2024-07-30 11:03:23
 */
@Controller
@RequestMapping("/transportRegistrationShiftSchedule")
public class TransportRegistrationShiftScheduleController extends BaseController {

    private String PREFIX = "/bi/transportRegistrationShiftSchedule";

    @Autowired
    private TransportRegistrationShiftScheduleService transportRegistrationShiftScheduleService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicOperateService basicOperateService;


    /**
     * 跳转到主页面
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("")
    public String index(Model model) {
        User user = userService.getcurrentUser();
        Long deptId = user.getDeptId();
        Long deliverId = user.getDeliverId();
        model.addAttribute("basicOperatelist", basicOperateService.findAvailableList(deptId, deliverId, user.getOperateId()));
        return PREFIX + "/transportRegistrationShiftSchedule.html";
    }

    /**
     * 新增页面
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/transportRegistrationShiftSchedule_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/transportRegistrationShiftSchedule_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TransportRegistrationShiftScheduleParam transportRegistrationShiftScheduleParam) {
        this.transportRegistrationShiftScheduleService.add(transportRegistrationShiftScheduleParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TransportRegistrationShiftScheduleParam transportRegistrationShiftScheduleParam) {
        this.transportRegistrationShiftScheduleService.update(transportRegistrationShiftScheduleParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TransportRegistrationShiftScheduleParam transportRegistrationShiftScheduleParam) {
        this.transportRegistrationShiftScheduleService.delete(transportRegistrationShiftScheduleParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TransportRegistrationShiftScheduleParam transportRegistrationShiftScheduleParam) {
        TransportRegistrationShiftSchedule detail = this.transportRegistrationShiftScheduleService.getById(transportRegistrationShiftScheduleParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author zhangzh
     * @Date 2024-07-30
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TransportRegistrationShiftScheduleParam transportRegistrationShiftScheduleParam,String condition ) {
        User user = userService.getcurrentUser();
        if(transportRegistrationShiftScheduleParam.getOperateId() == null && user.getOperateId() != null){
            user.setOperateId(user.getOperateId());
        }
        return this.transportRegistrationShiftScheduleService.findPageBySpec(transportRegistrationShiftScheduleParam,condition);
    }

    @ResponseBody
    @RequestMapping("/listAll")
    public List<TransportRegistrationShiftScheduleResult> listAll(TransportRegistrationShiftScheduleParam transportRegistrationShiftScheduleParam) {
        User user = userService.getcurrentUser();
        if(transportRegistrationShiftScheduleParam.getOperateId() == null && user.getOperateId() != null){
            user.setOperateId(user.getOperateId());
        }
        return this.transportRegistrationShiftScheduleService.findListBySpec(transportRegistrationShiftScheduleParam);
    }

}


